<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>非受控组件</title>
</head>
<body>
  <div id="test"></div>

  <!-- 引入库：先引入核心库，再引入操作DOM的扩展库 -->
  <script type="text/javascript" src="../js/react.development.js"></script>
  <script type="text/javascript" src="../js/react-dom.development.js"></script>
  <!-- 将jsx转为js -->
  <script type="text/javascript" src="../js/babel.min.js"></script>
  <script type="text/babel">    //必须写babel，因为默认js
    class Login extends React.Component{
      password = React.createRef()

      //非受控组件：现用现取
      handleSubmit = (event)=>{
        event.preventDefault()      //阻止默认事件，这里作用是阻止form表单的默认提交
        const {username} = this     //现用
        alert(`你输入的用户名是:${username.value}，你输入的密码是：${this.password.current.value}`)   //现取
      }
      render(){
        return(
          <form onSubmit={this.handleSubmit}>
            用户名：<input ref={c => this.username = c} type="text" name="usernamr"/>
            密码<input ref={this.password} type="password" name="password"/><br/>
            <button>登录</button>
          </form>
        )
      }
    }

    ReactDOM.render(<Login/>, document.getElementById('test'))
  </script>
</body>
</html>